package com.zzyl.nursing.controller.member;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.ElderAddDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.ElderBindedVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;


    @Autowired
    private IFamilyMemberElderService familyMemberElderService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    /**

     * 新增老人家属

     */


    @ApiOperation("绑定家人")//    @ApiOperation("新增老人家属")
//    @PreAuthorize("@ss.hasPermi('nursing:member:add')")
//    @Log(title = "老人家属", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@ApiParam(value = "老人家属实体")
//                          @RequestBody FamilyMember familyMember) {
//        return toAjax(familyMemberService.insertFamilyMember(familyMember));
//    }

    /**
     * 权限先注释掉。
     */
    //小程序端绑定老人接口。
//    @PreAuthorize("@ss.hasPermi('nursing:member:add')")
//    @Log(title = "老人家属", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R add(@ApiParam(value = "老人家属实体")
                          @RequestBody ElderAddDto elderAddDto) {
        return R.ok(familyMemberElderService.insertFamilyMemberElder(elderAddDto));
    }

    /**
     * 查询该会员关联的所有老人的所有房间，及设备信息。
     * @param
     * @return
     */
    @GetMapping("/list-by-page")
    public R getAllElders_Room_Devices() {
        startPage();
        List<ElderBindedVo> list = familyMemberElderService.listAll();
        return R.ok(list);
    }

    @GetMapping("/my")
    public R getBriefMemberAndElderInfos(){
        return R.ok(familyMemberElderService.listBriefInfo());
    }

}
